<?php
class BMSC_News extends BMSC_Db
{
	// Thêm tin tức vào database
	public function addNews($languageID, $title, $thumbnailImage, $summary, $isNew, $content, $source, $createBy)
	{
		try
		{
			$newsInfo = array();
			$newsInfo["LANGUAGE_ID"] = $languageID;
			$newsInfo["TITLE"] = $title;
			$newsInfo["THUMBNAIL_IMAGE"] = $thumbnailImage;
			$newsInfo["SUMMARY"] = $summary;
			$newsInfo["IS_NEW"] = $isNew;
			$newsInfo["CONTENT"] = $content;
			$newsInfo["SOURCE"] = $source;
			$newsInfo["CREATE_BY"] = $createBy;
			$newsInfo["CREATE_DATE"] = date("Y-m-d H:i:s");
			return $this->_writerDb->insert("news", $newsInfo);
		}
		catch (Exception $ex)
		{
			throw $ex;
		}
	}

	// Cập nhật tin tức vào database
	public function editNews($newsID, $languageID, $title, $thumbnailImage, $summary, $isNew, $content, $source, $updateBy)
	{
		try
		{
			$newsInfo = array();
			$newsInfo["LANGUAGE_ID"] = $languageID;
			$newsInfo["TITLE"] = $title;
			$newsInfo["THUMBNAIL_IMAGE"] = $thumbnailImage;
			$newsInfo["SUMMARY"] = $summary;
			$newsInfo["IS_NEW"] = $isNew;
			$newsInfo["CONTENT"] = $content;
			$newsInfo["SOURCE"] = $source;
			$newsInfo["UPDATE_BY"] = $updateBy;
			$newsInfo["UPDATE_DATE"] = date("Y-m-d H:i:s");
			return $this->_writerDb->update("news", $newsInfo, "ID=" . $newsID);
		}
		catch (Exception $ex)
		{
			throw $ex;
		}
	}

	// Xóa tin tức khỏi database
	public function removeNews($newsID, $updateBy)
	{
		try
		{
			$newsInfo = array();
			$newsInfo["IS_DELETE"] = 1;
			$newsInfo["UPDATE_BY"] = $updateBy;
			$newsInfo["UPDATE_DATE"] = date("Y-m-d H:i:s");
			return $this->_writerDb->update("news", $newsInfo, "ID=" . $newsID);
		}
		catch (Exception $ex)
		{
			throw $ex;
		}
	}

	// Lấy danh sách tin tức
	public function getNewsList($from, $numberOfNews)
	{
		try
		{
			$query = sprintf("CALL sp_admin_get_news_list(%u, %u)", $from, $numberOfNews);
			$news = $this->_readerDb->fetchAll($query);
			$this->_readerDb->closeConnection();
			return $news;
		}
		catch (Exception $ex)
		{
			throw $ex;
		}
	}

	// Lấy thông tin tin tức
	public function getNews($newsID)
	{
		try
		{
			$query = sprintf("CALL sp_admin_get_news(%u)", $newsID);
			$news = $this->_readerDb->fetchRow($query);
			$this->_readerDb->closeConnection();
			return $news;
		}
		catch (Exception $ex)
		{
			throw $ex;
		}
	}
}
?>